typedef struct Polynode  
{ 
  int coef; 
  int exp; 
  Polynode *next; 
}Polynode, *Polylist; 
 
void polycreate(Polylist head) 
{ 
	Polynode *rear, *s; 
	int c,e; 
	rear=head;
	scanf("%d,%d",&c,&e);
	while(c!=0)
	{ 
		s=(Polynode*)malloc(sizeof(Polynode));
		s->coef=c; 
		s->exp=e;  
		rear->next=s;
		rear=s; 
		scanf("%d,%d",&c,&e);  
	} 
		rear->next=NULL;
}
void  polyadd(Polylist polya, Polylist polyb) 
{ 
	Polynode  *p, *q, *pre, *temp; 
	int sum; 
	p=polya->next;
	q=polyb->next;         
	pre=polya;
	while (p!=NULL && q!=NULL)
	{  
		if  (p->exp < q->exp) 
		{  
			pre->next=p;   
			pre=p;  
			p=p->next; 
		}
		else if(p->exp==q->exp)
		{   
			sum=p->coef + q->coef; 
			if(sum != 0) 
			{  
				p->coef=sum; 
				pre->next=p;  
				pre=p; 
				p=p->next; 
				temp=q;  
				q=q->next;  
				free(temp); 
			} 
        else 
        { 
				temp=p; 
				p=p->next; 
				free(temp);  
				temp=q;  
				q=q->next; 
				free(temp); 
        } 
	} 
	else 
    {   
		pre->next=q; 
		pre=q;
        q = q->next;  
	} 
 }
  if(p!=NULL)
    pre->next=p; 
  else
    pre->next=q; 
}

void polyshow(Polylist p)
{
	while(p->next)
	{
		if(p->exp&&p->exp!=1) printf("%dx^%d",p->coef,p->exp);
		else if(p->exp==1) printf("%dx",p->coef);
		else printf("%d",p->coef);
		if(p->next->coef>=0) printf("+");
		p=p->next;
	}
		if(p->exp&&p->exp!=1) printf("%dx^%d",p->coef,p->exp);
		else if(p->exp==1) printf("%dx",p->coef);
		else printf("%d");
		printf("\n");
}